home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / Random / p_random_init.m < prev    next >
Text File  |  1992-04-27  |  1KB  |  61 lines

  1. /******************************************************************************
  2.  
  3.    A portable plural random number generator based on three linear
  4.    congruential generators.  -- Numerical Recipes in C pp. 210
  5.  
  6.    Copyright 1991,1992 Lee Iverson
  7.  
  8.    Author:
  9.      Lee Iverson <leei@mcrcim.mcgill.edu>,
  10.      McGill Research Centre for Intelligent Machines (McRCIM)
  11.  
  12.    See "copyright.h" for complete copyright information.
  13.  
  14. ******************************************************************************/
  15.  
  16. static char RCSid[] =
  17.   "$Id: p_random_init.m,v 1.2 92/01/23 17:34:14 leei Exp $";
  18.  
  19. #include "copyright.h"
  20.  
  21. #include <values.h>
  22. #include <math.h>
  23.  
  24. #include <sys/time.h>
  25.  
  26. #include "p_randomI.h"
  27.  
  28. char rand_init__ = 0;
  29. plural long ix1__, ix2__, ix3__;
  30. plural float r__[98];
  31.  
  32. /* Initialize the random number generator from time of day. */
  33. void
  34. init_p_random(seed)
  35. int seed;
  36. {
  37.     register plural long p_seed;
  38.     register int j;
  39.  
  40.     if ( seed ) {
  41.     p_seed = seed + 17*iproc;
  42.     } else {
  43.     struct timeval t;
  44.     struct timezone tz;
  45.     gettimeofday(&t,&tz);
  46.     p_seed = t.tv_sec+17*iproc;
  47.     }
  48.  
  49.     ++rand_init__;
  50.     ix1__ = (IC1 + p_seed) % M1;
  51.     ix1__ = (IA1*ix1__ + IC1) % M1;
  52.     ix2__ = ix1__ % M2;
  53.     ix1__ = (IA1*ix1__ + IC1) % M1;
  54.     ix3__ = ix1__ % M3;
  55.     for ( j=1; j < 98; ++j ) {
  56.     ix1__ = (IA1*ix1__ + IC1) % M1;
  57.     ix2__ = (IA2*ix2__ + IC2) % M2;
  58.     r__[j] = (ix1__+ix2__*RM2)*RM1;
  59.     }
  60. }
  61.